//
//  LZQ_ProgressHUD.swift
//  SwiftExercise
//
//  Created by King on 2021/6/18.
//

import UIKit

enum MyHUDStatus {
    case success
    case error
    case info
    case waitting
    case onlyText
    case progress
}

class LZQ_ProgressHUD: NSObject {
    
    
    /// 纯文字提示
    /// - Parameter msg: 提示文字
    static func showTipMessage(_ msg:String?){
        showWithStatus(hudStatus: .onlyText, text: msg, progress: 0)
    }
    
    /// 带感叹号的提示
    /// - Parameter msg: 提示文字
    static func showInfoMsg(_ msg:String?){
        showWithStatus(hudStatus: .info, text: msg, progress: 0)
    }
    
    /// 错误的提示
    /// - Parameters:
    ///   - msg: 内容
    static func showFailure(_ msg:String){
        showWithStatus(hudStatus: .error, text: msg, progress: 0)
    }
    
    /// 成功的提示
    /// - Parameter msg: 提示文字
    static func showSuccess(_ msg:String){
        showWithStatus(hudStatus: .success, text: msg, progress: 0)
    }
    
    /// 加载
    /// - Parameter msg: 提示文字
    static func showWaiting(_ msg:String){
        showWithStatus(hudStatus: .waitting, text: msg, progress: 0)
    }
    
    
    static func showProgress(_ msg:String?,progress:CGFloat){
        showWithStatus(hudStatus: .progress, text: msg, progress: progress)
    }
    
    static func hideNow(){
        SVProgressHUD.dismiss()
    }
    
    static func showWithStatus(hudStatus status:MyHUDStatus,text msg:String?,progress:CGFloat){
        SVProgressHUD.setDefaultStyle(.dark)
        
        
        switch status {
        case .success:
            SVProgressHUD.setDefaultMaskType(.clear)
            SVProgressHUD.setSuccessImage(UIImage(named: "me")!)
            SVProgressHUD.showSuccess(withStatus: msg)
            SVProgressHUD.setMinimumSize(CGSize(width: 100, height: 80))
            SVProgressHUD.dismiss(withDelay: 1.5)
            break
            
        case .error:
            SVProgressHUD.setDefaultMaskType(SVProgressHUDMaskType.none)
            SVProgressHUD.setSuccessImage(UIImage(named: "me")!)
            SVProgressHUD.dismiss(withDelay: 1.5)
            break
        case .info:
            SVProgressHUD.setDefaultMaskType(SVProgressHUDMaskType.none)
            SVProgressHUD.setMinimumSize(CGSize(width: 100, height: 80))
            SVProgressHUD.setSuccessImage(UIImage(named: "me")!)
            SVProgressHUD.showInfo(withStatus: msg)
            SVProgressHUD.dismiss(withDelay: 1.5)
            break
        case .waitting:
            SVProgressHUD.setDefaultMaskType(SVProgressHUDMaskType.clear)
            SVProgressHUD.show(withStatus: msg)
            break
        case .onlyText:
            SVProgressHUD.setDefaultMaskType(SVProgressHUDMaskType.none)
//            SVProgressHUD.setSuccessImage(UIImage(named: "me")!)
            SVProgressHUD.setErrorImage(UIImage(named: "me")!)
            SVProgressHUD.showInfo(withStatus: msg)
            SVProgressHUD.dismiss(withDelay: 1.5)
            break
        case .progress:
            SVProgressHUD.setDefaultMaskType(SVProgressHUDMaskType.none)
            SVProgressHUD.showProgress(Float(progress), status: msg)
            break
        }
    }
}
